package com.guigu.youxuan.controller;

import com.guigu.youxuan.pojo.BackUserRole;
import com.guigu.youxuan.service.IBackUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@RestController
@RequestMapping("/backUserRole")
public class BackUserRoleController {
    @Autowired
    private IBackUserRoleService backUserRoleService;

    /**
     * 当前用户角色的查询
     * @param userId
     * @return
     */
    @RequestMapping("/queryBackUserRoleByUserId/{userId}")
    public List<BackUserRole> queryBackUserRoleByUserId(@PathVariable Long userId) {
        List<BackUserRole> backUserRoleList= backUserRoleService.queryBackUserRoleByUserId(userId);
        return backUserRoleList;
    }

    /**
     * 分配角色
     * @param roleIds
     * @return
     */
    @RequestMapping("/assignRoles/{userId}")
    public String assignRoles(@RequestBody List<Long> roleIds,
                              @PathVariable Long userId) {
        backUserRoleService.addUserRole(roleIds, userId);
        return "该用户分配角色成功！";
    }
}
